package bridges;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Vector;


public class BridgesCollection {
	
	Map<Long,CommunicationBridge> bridges;
	
	public BridgesCollection()
	{
		bridges = new HashMap<Long, CommunicationBridge>();
	}
	
	public void addBridge(Long id,CommunicationBridge bridge)
	{
		this.bridges.put(id, bridge);
	}
	
	public CommunicationBridge removeBridge(Long id)
	{
		return this.bridges.remove(id);
	}
	
	public CommunicationBridge getBridge(Long id)
	{
		return this.bridges.get(id);
	}

	public Set<CommunicationBridge> getAllOuts(Map<String,Boolean> userNames)
	{
		Set<CommunicationBridge> ans = new HashSet<CommunicationBridge>();
		for (CommunicationBridge bridge : this.bridges.values()) 
		{
			String userName = bridge.getUserName();
			boolean userExsist = userNames.containsKey(userName);
			if (userName != null && userExsist)
			{
				ans.add(bridge);
			}
		}
		return ans;
	}

	public Vector<CommunicationBridge> getAllOutsInSubForum(int subForumId,boolean isSubForum) {
		Vector<CommunicationBridge> ans = new Vector<CommunicationBridge>();
		for (CommunicationBridge bridge : this.bridges.values()) {
			if ((isSubForum&&bridge.getUserSubForum() == subForumId) ||(!isSubForum && bridge.getThreadForum() == subForumId) )
			{
				ans.add(bridge);
			}
		}
		return ans;
	}
	
	public boolean contains(Long id)
	{
		return this.bridges.containsKey(id);
	}
	
	

}
